import { PageHeaderWrapper } from '@ant-design/pro-layout';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { queryTollerSignRecords } from '../service';
import type { TollerSignInRecordTableItem } from '../types';

export default () => {
  const columns: ProColumns<TollerSignInRecordTableItem>[] = [
    {
      title: 'id',
      dataIndex: '_id',
      hideInForm: true,
      hideInSearch: true,
      hideInTable: true,
    },
    {
      title: '员工编号',
      dataIndex: 'jobNo',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '员工姓名',
      dataIndex: 'name',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '签到类型',
      dataIndex: 'signType',
      hideInForm: true,
      valueEnum: {
        1: { text: '上班', status: 'Success' },
        2: { text: '下班', status: 'Default' },
      },
      align: 'center',
    },
    {
      title: '签到机器',
      dataIndex: 'posSN',
      hideInForm: true,
      hideInSearch: true,
      align: 'center',
    },
    {
      title: 'APP版本',
      dataIndex: 'apkVersion',
      hideInForm: true,
      hideInSearch: true,
      align: 'center',
    },
    {
      title: '签到地点',
      dataIndex: 'street',
      hideInForm: true,
      hideInSearch: true,
      align: 'center',
    },
    {
      title: '签到状态',
      dataIndex: 'signStatus',
      hideInForm: true,
      valueEnum: {
        // true: { text: '范围内', status: 'success' },
        // false: { text: '超出范围', status: 'error' },
        0b00: { text: '正常', status: 'success' },
        0b01: { text: '超出范围', status: 'warning' },
        0b10: { text: '迟到', status: 'error' },
        0b11: { text: '迟到且超出范围', status: 'default' },
      },
      align: 'center',
    },
    {
      title: '签到点坐标',
      dataIndex: 'location',
      hideInForm: true,
      hideInSearch: true,
      align: 'center',
      render: (_, record) => record.location?.join('，'),
    },
    {
      title: '签到时间',
      dataIndex: 'createTime',
      hideInForm: true,
      hideInSearch: true,
      valueType: 'dateTime',
      align: 'center',
    },
    {
      title: '班次时间',
      dataIndex: 'shiftTime',
      hideInForm: true,
      hideInSearch: true,
      valueType: 'dateTime',
      align: 'center',
    },
  ];
  return (
    <PageHeaderWrapper
      header={{
        title: '',
        subTitle: '收费人员考勤列表',
        breadcrumb: {
          routes: [
            {
              path: '/',
              breadcrumbName: '首页',
            },
            {
              path: '/staff',
              breadcrumbName: '员工管理',
            },
            {
              path: '/staff/signin-record',
              breadcrumbName: '考勤记录',
            },
          ],
        },
      }}
    >
      <ProTable<TollerSignInRecordTableItem>
        columns={columns}
        search={{
          labelWidth: 'auto',
        }}
        scroll={{ x: true }}
        style={{ whiteSpace: 'nowrap' }}
        rowKey="_id"
        columnEmptyText="暂无数据"
        debounceTime={300}
        request={async (param, sort) => {
          const res = await queryTollerSignRecords(param, sort);
          return res;
        }}
        dateFormatter="string"
        pagination={{
          showSizeChanger: true,
          showQuickJumper: true,
          defaultPageSize: 10,
          size: 'default',
        }}
      />
    </PageHeaderWrapper>
  );
};
